package kuzmenkov.oip.model.dao.hibernate.impl;

import kuzmenkov.oip.model.User;
import kuzmenkov.oip.model.dao.hibernate.UserDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.springframework.dao.DataAccessException;

import java.util.List;

/**
 * @see kuzmenkov.oip.model.dao.hibernate.UserDao
 * User: Michael Kuzmenkov
 * Date: 16.03.2009
 * Time: 12:05:03
 */
public class UserDaoImpl extends GenericDaoImpl<User,Long> implements UserDao {

    /**
     * @see kuzmenkov.oip.model.dao.hibernate.UserDao#findByName(String) 
     */
    @Override
    public List<User> findByName(String name) throws DataAccessException {
        User obj = null;
        DetachedCriteria criteria = DetachedCriteria.forClass(User.class);
        criteria.add(Expression.eq("name", name));

        List objs = getHibernateTemplate().findByCriteria(criteria);
                       
        return objs;
        
    }

    /**
     * @see kuzmenkov.oip.model.dao.hibernate.UserDao#findByEmail(String) 
     */
    @Override
    public List<User> findByEmail(String email) throws DataAccessException {
        User obj = null;
        DetachedCriteria criteria = DetachedCriteria.forClass(User.class);
        criteria.add(Expression.eq("email",email));

        List objs = getHibernateTemplate().findByCriteria(criteria);

        return objs;

    }

}
